using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace EngineGame
{
    public struct Size
    {
        public int Width;
        public int Height;
    }
    class Sprite
    {
        private int type;
        private SpriteEffects effectType;
        private int speed;
        private int timecurrent;
        public SpriteEffects EffectType
        {
            get { return effectType; }
            set { effectType = value; }
        }

        public int Type
        {
            get { return type; }
            set { type = value; }
        }

        private Texture2D textureImage;

        public Texture2D TexttureImage
        {
            get { return textureImage; }
            set { textureImage = value; }
        }
        private Size size;
        private Vector2 position;

        public float X
        {
            get { return position.X; }
            set { position.X = value; }
        }
        public float Y
        {
            get { return position.Y; }
            set { position.Y = value; }
        }

        public Vector2 Position
        {
            get { return position; }
            set { position = value; }
        }

        public Size Size
        {
            get { return size; }
            set { size = value; }
        }
        
        public int Speed
        {
            get { return speed; }
            set { speed = value; }
        }
        
        private int sizeFrame;
        private int currentFrame;
        public int CurrentFrame
        {
            get { return currentFrame; }
            set { currentFrame = value; }
        }

        public Sprite(Sprite Obj)
        {
            this.speed = 0;
            this.type = Obj.type;
            this.textureImage = Obj.textureImage;
            this.size = Obj.size;
            this.position = Obj.position;
            this.sizeFrame = Obj.sizeFrame;
            effectType = Obj.effectType;
        }
        public Sprite(ContentManager content, string path)
        {
            this.speed = 0;
            sizeFrame = 1;
            LoadContent(content, path);
            currentFrame = 0;
            size.Width = textureImage.Width;
            size.Height = textureImage.Height;
            EffectType = SpriteEffects.None;
        }
        public Sprite(ContentManager content, string path, int sizeFrame)
        {
            this.speed = 200;
            this.sizeFrame = sizeFrame;
            LoadContent(content, path);
            currentFrame = 0;
            size.Width = textureImage.Width / sizeFrame;
            size.Height = textureImage.Height;
            EffectType = SpriteEffects.None;
        }
        public void LoadContent(ContentManager content, string path)
        {
            textureImage = content.Load<Texture2D>(path);
        }
        public bool Next(GameTime gametime)
        {
            timecurrent += gametime.ElapsedGameTime.Milliseconds;
            if (timecurrent >= speed || timecurrent<0)
            {
                if ((currentFrame) < (sizeFrame-1))
                {
                    currentFrame++;
                }
                else
                    currentFrame = 0;
                timecurrent = 0;
                return true;
            }
            return false;
        }
        public void Draw(SpriteBatch spriteBatch, float scale)
        {
            spriteBatch.Draw(textureImage, position, new Rectangle(currentFrame * size.Width, 0, (int)size.Width, (int)size.Height), Color.White, 0, new Vector2(0, 0), scale, effectType, 0);
        }
        public void Draw(SpriteBatch spriteBatch, float rotate, Vector2 origin)
        {
            spriteBatch.Draw(textureImage, position, new Rectangle(currentFrame * size.Width, 0, (int)size.Width, (int)size.Height), Color.White, rotate, origin, 1, effectType, 0);
        }
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(textureImage, position, new Rectangle(currentFrame * size.Width, 0, (int)size.Width, (int)size.Height), Color.White);
        }
        public void Draw(SpriteBatch spriteBatch, Color color)
        {
            spriteBatch.Draw(textureImage, position, new Rectangle(currentFrame * size.Width, 0, (int)size.Width, (int)size.Height), color);
        }
        public void Draw(SpriteBatch spriteBatch, Vector2 position)
        {
            spriteBatch.Draw(textureImage, position, new Rectangle(currentFrame * size.Width, 0, (int)size.Width, (int)size.Height), Color.White);
        }
        public void Draw(SpriteBatch spriteBatch, Rectangle des, int currentFrame)
        {
            spriteBatch.Draw(textureImage, des, new Rectangle(currentFrame * size.Width, 0, (int)size.Width, (int)size.Height), Color.White);
        }
        public void Draw(SpriteBatch spriteBatch, Vector2 origin, Vector2 scale, int currentFrame)
        {
            spriteBatch.Draw(textureImage, position, new Rectangle(currentFrame * size.Width, 0, (int)size.Width, (int)size.Height), Color.White, 0, origin, scale, effectType, 0);
        }
        public void Draw(SpriteBatch spriteBatch, Vector2 origin, float scale)
        {
            spriteBatch.Draw(textureImage, position, new Rectangle(currentFrame * size.Width, 0, (int)size.Width, (int)size.Height), Color.White, 0, origin, scale, effectType, 0);
        }
        public void Draw(SpriteBatch spriteBatch, Vector2 pos, Vector2 origin, float scale)
        {
            spriteBatch.Draw(textureImage, pos, new Rectangle(currentFrame * size.Width, 0, (int)size.Width, (int)size.Height), Color.White, 0, origin, scale, effectType, 0);
        }
    }
}
